package com.taiyi.renaissancemall.ui.main.paysuccess


import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.taiyi.renaissancemall.R
import com.taiyi.renaissancemall.adapter.AdapterManager
import com.taiyi.renaissancemall.adapter.baseadapter.MultiItemTypeAdapter
import com.taiyi.renaissancemall.base.BaseActivity
import com.taiyi.renaissancemall.bean.PaySuccessBean
import com.taiyi.renaissancemall.ui.main.goodsdetail.GoodsDetailActivity
import com.taiyi.renaissancemall.ui.mine.order.MyOrderActivity
import kotlinx.android.synthetic.main.activity_pay_success.*
import kotlinx.android.synthetic.main.base_top_white_background_layout.*

class PaySuccessActivity : BaseActivity<PaySuccessView, PaySuccessPresent>(), PaySuccessView,
    MultiItemTypeAdapter.OnItemClickListener {


    override fun getLayoutId(): Int = R.layout.activity_pay_success
    override fun initPresenter(): PaySuccessPresent = PaySuccessPresent()
    var data = mutableListOf<PaySuccessBean.ComlistBean>()
    override fun initImmersionBar() {
        super.initImmersionBar()
        mImmersionBar.titleBar(top).init()
    }

    override fun initViews(savedInstanceState: Bundle?) {
        titleTv.text = getString(R.string.paySuccess)
        backIv.setOnClickListener { finish() }
        var payWay = intent.getStringExtra("payWay")
        var payAmount = intent.getStringExtra("payAmount")
        when (payWay) {
            "2" -> payWayTv.text = getString(R.string.payWay) + " " + getString(R.string.aliPay)
            "3" -> payWayTv.text =
                getString(R.string.payWay) + " " + getString(R.string.balance)
            "1" -> payWayTv.text =
                getString(R.string.payWay) + " " + getString(R.string.weChat)
        }
        payAmountTv.text = getString(R.string.payAmount) + " ￥$payAmount"

    }

    override fun initData() {
        showProgress()
        presenter.findOrderState()
    }

    override fun initEvent() {
        viewOrderDetailTv.setOnClickListener {
            var intent = Intent(this, MyOrderActivity::class.java)
            intent.putExtra("type", 1)
            startActivity(intent)
            finish()
        }
    }

    override fun getOrderStateSuccess(paySuccessBean: PaySuccessBean?) {
        hideProgress()
        levelTv.text = paySuccessBean?.shengjistr
        var comlist = paySuccessBean?.comlist
        data.clear()
        data.addAll(comlist!!)
        recyclerView.layoutManager = LinearLayoutManager(this)
        var paySuccessListAdapter = AdapterManager.getPaySuccessListAdapter(this, data)
        recyclerView.adapter = paySuccessListAdapter
        paySuccessListAdapter.setOnItemClickListener(this)
    }

    override fun getOrderStateFailure(msg: String?) {
        hideProgress()
        toast(msg)
    }

    override fun getOrderId(): String = intent.getStringExtra("orderId")
    override fun onItemLongClick(
        view: View?,
        holder: RecyclerView.ViewHolder?,
        position: Int
    ): Boolean {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onItemClick(view: View?, holder: RecyclerView.ViewHolder?, position: Int) {
        var intent = Intent(this, GoodsDetailActivity::class.java)
        var bundle = Bundle()
        bundle.putString("commodityId", data[position].commodityid)
        intent.putExtras(bundle)
        startActivity(intent)
    }
}
